package cn.tedu.ivos.user.util;

import java.security.SecureRandom;
//密码工具类，生成随机密码
public class PasswordUtil {
    //定义出现在密码中 的数字集合
    private static final String ALLOWED_CHARS =
            "1234567890ABCDEFGHIJKLMNOPQRSTUVWKYSabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+;";
   //生成随机数
    private  static final SecureRandom random = new SecureRandom();
//生成指定位数随机密码
    public  static  String generateRandomPassword(int length) {
        if (length < 5) throw new RuntimeException("密码长度不能小于5");
        StringBuilder password = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(ALLOWED_CHARS.length());
            char randomChar = ALLOWED_CHARS.charAt(index);
            password.append(randomChar);
        }
        return password.toString();
    }
    }

